package com.lgl.sqlSession.impl;

import com.lgl.config.XMLConfigBuilder;
import com.lgl.prjo.Configuration;
import com.lgl.sqlSession.ISqlSessionFactory;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;

public class SqlSessionFactoryBuilder {

    public ISqlSessionFactory build(InputStream in) throws PropertyVetoException, DocumentException {
        //第一；使用dom4j解析配置文件， 将解析出来的内容封装到Configuration中
        XMLConfigBuilder xmlConfigBuilder = new XMLConfigBuilder();
        Configuration configuration = xmlConfigBuilder.parseConfig(in);

        //第二： 创建sql
        DefaultSqlSessionFactory defautlSqlSessionFactory = new DefaultSqlSessionFactory(configuration);
        return  defautlSqlSessionFactory;
    }
}
